#include <mFS/FsTypes.h>

#include "APDUParse.h"
#include "SwCode.h"

#include <cmd/CMDDevice.h>
#include <cmd/CMDAuth.h>
#include <cmd/CMDApplication.h>
#include <cmd/CMDFile.h>
#include <cmd/CMDContainer.h>
#include <cmd/CMDCryptAsymCipher.h>
#include <cmd/CMDCryptSession.h>
#include <cmd/CMDCryptRandom.h>
#include <cmd/CMDCryptDigest.h>
#include <cmd/CMDCryptSymCipher.h>
#include <cmd/CMDCryptMac.h>

#include "ApduProc_Handler_GM.h"


void ApduProc_Handler_GM(UINT8 Ins)
{
	switch(Ins)
	{
		case CMD_DEV_SETDEVINFO:
			CMDDevice_SetDevInfo();
			break;
		case CMD_DEV_GETDEVINFO:
			CMDDevice_GetDevInfo();
			break;

		case CMD_AUTH_DEVAUTH:
			CMDAuth_DevAuth();
			break;
		case CMD_AUTH_CHANGEDEVAUTHKEY:
			CMDAuth_ChangeDevAuthKey();
			break;
		case CMD_AUTH_GETPININFO:
			CMDAuth_GetPinInfo();
			break;
		case CMD_AUTH_CHANGEPIN:
			CMDAuth_ChangePin();
			break;
		case CMD_AUTH_VERFYPIN:
			CMDAuth_VerifyPin();
			break;
		case CMD_AUTH_UNBLOCKPIN:
			CMDAuth_UnblockPin();
			break;
		case CMD_AUTH_CLEARSECUERSTATE:
			CMDAuth_ClearSecureState();
			break;

		case CMD_APP_CREATEAPP:
			CMDApplication_CreateApp();
			break;
		case CMD_APP_ENUMAPP:
			CMDApplication_EnumApps();
			break;
		case CMD_APP_DELETEAPP:
			CMDApplication_DeleteApp();
			break;
		case CMD_APP_OPENAPP:
			CMDApplication_OpenApp();
			break;
		case CMD_APP_CLOSEAPP:
			CMDApplication_CloseApp();
			break;

		case CMD_FILE_CREATEFILE:
			CMDFile_CreateFile();
			break;
		case CMD_FILE_DELETEFILE:
			CMDFile_DeleteFile();
			break;
		case CMD_FILE_ENUMFILES:
			CMDFile_EnumFiles();
			break;
		case CMD_FILE_GETFILEINFO:
			CMDFile_GetFileInfo();
			break;
		case CMD_FILE_READFILE:
			CMDFile_ReadFile();
			break;
		case CMD_FILE_WRITEFILE:
			CMDFile_WriteFile();
			break;

		case CMD_CONTAINER_CREATECONTAINER:
			CMDContainer_CreateContainer();
			break;
		case CMD_CONTAINER_OPENCONTAINER:
			CMDContainer_OpenContainer();
			break;
		case CMD_CONTAINER_CLOSECONTAINER:
			CMDContainer_CloseContainer();
			break;
		case CMD_CONTAINER_ENUMCONTAINERS:
			CMDContainer_EnumContainers();
			break;
		case CMD_CONTAINER_DELETECONTAINER:
			CMDContainer_DeleteContainer();
			break;
		case CMD_CONTAINER_GETCONTAINERINFO: 
			CMDContainer_GetContainerInfo();
			break;
		case CMD_CONTAINER_IMPORTCONTAINER:
			CMDContainer_ImportCertificate();
			break;
		case CMD_CONTAINER_EXPORTCONTAINER:
			CMDContainer_ExportCertificate();
			break;

		case CMD_CRYPT_GETREALRANDOM:
			CMDCryptRandom_GetRealRandom();
			break;
		case CMD_CRYPT_GENRSAKEYPAIR:
			CMDCryptAsymCipher_GenRSAKeyPair();
			break;
		case CMD_CRYPT_IMPORTRSAKEYPAIR:
			CMDCryptAsymCipher_ImportRSAKeyPair();
			break; 
		case CMD_CRYPT_RSASIGNDATA:
			CMDCryptAsymCipher_RSASignData();
			break;
		case CMD_CRYPT_RSAVERIFY:
			CMDCryptAsymCipher_RSAVerify();
			break;
		case CMD_CRYPT_RSAEXPORTSESSIONKEY:
			CMDCryptAsymCipher_RSAExportSessionKey();
			break;
		case CMD_CRYPT_RSAEXPORTSESSIONKEYEX:
			CMDCryptAsymCipher_RSAExportSessionKeyEx();
			break;
		case CMD_CRYPT_EXTRSAPUBKEYOPERATION:
			CMDCryptAsymCipher_ExtRSAPubKeyOperation();
			break;

		case CMD_CRYPT_GENECCKEYPAIR:
			CMDCryptAsymCipher_GenECCKeyPair();
			break;
		case CMD_CRYPT_IMPORTSM2KEYPAIR:
			CMDCryptAsymCipher_ImportSM2KeyPair();//
			break;
		case CMD_CRYPT_ECCSIGNDATA:
			CMDCryptAsymCipher_ECCSignData();//
			break;
		case CMD_CRYPT_ECCVERIFY:
			CMDCryptAsymCipher_ECCVerify();
			break;
		case CMD_CRYPT_SM2EXPORTSESSIONKEY:
			CMDCryptAsymCipher_SM2ExportSessionKey();
			break;
		case CMD_CRYPT_SM2EXPORTSESSIONKEYEX:
			CMDCryptAsymCipher_SM2ExportSessionKeyEx();
			break;
		case CMD_CRYPT_EXTSM2ENCRYPT:
			CMDCryptAsymCipher_ExtSM2Encrypt();
			break;
		case CMD_CRYPT_GENERATEAGREEMENTDATAWITHSM2:
			CMDCryptAsymCipher_GenerateAgreementDataWithSM2();
			break;
		case CMD_CRYPT_GENERATEAGREEMENTDATAANDKEYWITHSM2:
			CMDCryptAsymCipher_GenerateAgreementDataAndKeyWithSM2();
			break;
		case CMD_CRYPT_GENERATEKEYWITHSM2:
			CMDCryptAsymCipher_GenerateKeyWithSM2();
			break;
		case CMD_CRYPT_EXPORTPUBLICKEY:
			CMDCryptAsymCipher_ExportPublicKey();
			break;
		case CMD_CRYPT_IMPORTSESSIONKEY:
			CMDCryptAsymCipher_ImportSessionKey();
			break;

		case CMD_CRYPT_ENCRYPTINIT:
			CMDCryptSymCipher_EncryptInit();
			break;
		case CMD_CRYPT_ENCRYPT:
			CMDCryptSymCipher_Encrypt();
			break;
		case CMD_CRYPT_ENCRYPTUPDATE:
			CMDCryptSymCipher_EncryptUpdate();
			break;
		case CMD_CRYPT_ENCRYPTFINAL:
			CMDCryptSymCipher_EncryptFinal();
			break;
		case CMD_CRYPT_DECRYPTINIT:
			CMDCryptSymCipher_DecryptInit();
			break;
		case CMD_CRYPT_DECRYPT:
			CMDCryptSymCipher_Decrypt();
			break;
		case CMD_CRYPT_DECRYPTUPDATE:
			CMDCryptSymCipher_DecryptUpdate();
			break;
		case CMD_CRYPT_DECRYPTFINAL:
			CMDCryptSymCipher_DecryptFinal();
			break;	

		case CMD_CRYPT_DIGESTINIT:
			CMDCryptDigest_DigestInit();
			break;
		case CMD_CRYPT_DIGEST:
			CMDCryptDigest_Digest();
			break;
		case CMD_CRYPT_DIGESTUPDATE:
			CMDCryptDigest_DigestUpdate();
			break;
		case CMD_CRYPT_DIGESTFINAL:
			CMDCryptDigest_DigestFinal();
			break;

		case CMD_CRYPT_MACINIT:
			CMDCryptMac_MacInit();
			break;
		case CMD_CRYPT_MAC:
			CMDCryptMac_Mac();
			break;
		case CMD_CRYPT_MACUPDATE:
			CMDCryptMac_MacUpdate();
			break;
		case CMD_CRYPT_MACFINAL:
			CMDCryptMac_MacFinal();
			break;
		case CMD_CRYPT_DESTROYSESSIONKEY:
			CMDCryptSession_DestroySessionKey();
			break;

		default:
			APDU_SetRespond(0, ISOSW_INS_ERROR);
			break;
	}

	return ;
}
